<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
  <head>
	<meta charset="utf-8">
    <title>bubble chart</title>
	<script src="../js/d3.v3.min.js"></script>

  <link rel="stylesheet" href="../bubble/css/d3.bubble.css" type="text/css"></link>
 
<style>
#chartPanel {
	float: left; 
}
#controlPanel { 
	position: absolute;
	right: 10px;
	top: 10px;
	width: 130px;
}
.legend {
	font-size: 20px;
} 
</style>
  <s:head/>
  </head>

  <body>
  
  <div id="chartPanel"></div>
  <div id="controlPanel">
  	
  	<form action="<s:url action="fileUpload" namespace="/bubble"/>" method="post" enctype="multipart/form-data">
  		<input type="hidden" name="destPage" value="<%= request.getServletPath()%>" />
  		<div>
  			<label for="dataFile">data file</label>
  			<s:file name="data" />
  		</div>
  		<div>
  			<input type="submit"/>
  		</div>
  	</form>
  </div>
  
<script>

var diameter = 960,
format = d3.format(",d"),
color = d3.scale.category20c();

var bubble = d3.layout.pack()
.sort(null)
.size([diameter, diameter])
.padding(1.5);

var svg = d3.select("#chartPanel").append("svg")
.attr("width", diameter)
.attr("height", diameter)
.attr("class", "bubble");

d3.json('<s:property value="#session['CURRENT_FILE']"/>', function(error, root) {
var node = svg.selectAll(".node")
  .data(bubble.nodes(classes(root))
  .filter(function(d) { return !d.children; }))
.enter().append("g")
  .attr("class", "node")
  .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });

node.append("title")
  .text(function(d) { return d.className + ": " + format(d.value); });

node.append("circle")
  .attr("r", function(d) { return d.r; })
  .style("fill", function(d) { return color(d.packageName); });

node.append("text")
  .attr("dy", ".3em")
  .style("text-anchor", "middle")
  .text(function(d) { return d.className.substring(0, d.r / 3); });
});

//Returns a flattened hierarchy containing all leaf nodes under the root.
function classes(root) {
var classes = [];

function recurse(name, node) {
if (node.children) node.children.forEach(function(child) { recurse(node.name, child); });
else classes.push({packageName: name, className: node.name, value: node.size});
}

recurse(null, root);
return {children: classes};
}

d3.select(self.frameElement).style("height", diameter + "px");
</script>
  
  
  </body>
</html>



















